/*
 * $Id: UserSearchCriteria.java 14 2014-08-15 11:50:17Z ratking $
 *
 * Copyleft (C) 2014 RatKing. All wrongs reserved.
 */
package cn.ratking.demo.jaws7.system.vo;

import java.io.Serializable;
import java.util.Date;

import javax.inject.Named;

import org.omnifaces.cdi.ViewScoped;

import cn.ratking.demo.jaws7.common.DateUtils;

/**
 * 用户查询条件
 */
@Named
@ViewScoped
public class UserSearchCriteria implements Serializable {

    /** 用户名 */
    private String username;
    /** 性别(0-未知的性别 1-男性 2-女性) */
    private String sex;
    /** 生日开始 */
    private Date birthdayBegin;
    /** 生日结束 */
    private Date birthdayEnd;

    /** 无参构造方法 */
    public UserSearchCriteria() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Date getBirthdayBegin() {
        return birthdayBegin;
    }

    public void setBirthdayBegin(Date birthdayBegin) {
        this.birthdayBegin = birthdayBegin;
    }

    public Date getBirthdayEnd() {
        return birthdayEnd;
    }

    public void setBirthdayEnd(Date birthdayEnd) {
        this.birthdayEnd = birthdayEnd;
    }

    /**
     * 检查调整查询条件中的开始与结束时间
     */
    public void checkDate() {
        // 检查并确保birthdayBegin在birthdayEnd之前，并调整其时分秒
        if (birthdayBegin != null && birthdayEnd != null
                && birthdayBegin.after(birthdayEnd)) {
            Date tmpDate = birthdayBegin;
            birthdayBegin = birthdayEnd;
            birthdayEnd = tmpDate;
        }
        if (birthdayBegin != null) {
            birthdayBegin = DateUtils.getBeginDate(birthdayBegin);
        }
        if (birthdayEnd != null) {
            birthdayEnd = DateUtils.getEndDate(birthdayEnd);
        }
    }

    /**
     * 返回测试字符串
     *
     * @return 测试字符串
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append("[UserSearchCriteria: username=").append(username);
        sb.append(", sex=").append(sex);
        sb.append(", birthdayBegin=").append(birthdayBegin);
        sb.append(", birthdayEnd=").append(birthdayEnd);
        sb.append("]");

        return sb.toString();
    }
}
